const mongoose = require('mongoose')

const User =require("./user.js")

const rankrSchema = new mongoose.Schema({
    user_id: {
        type: mongoose.Schema.Types.ObjectId,
        ref: "User"
    },
    test_grade:{
        type: Number,
        required: [true, "几年级"] 
    },
    test_project:{
        type: Number,
        required: [true, "科目"] 
    },
    test_type:{
        type: Number,
        required: [true, "考试类型"] ,

    },
    test_rank: {
        type: Number,
        required: [true, "填写成绩"]
    },
	test_rank1: {
	    type: Number,
	    required: [true, "填写成绩"]
	},
	test_rank2: {
	    type: Number,
	    required: [true, "填写成绩"]
	},
    test_name: {
        type: String
    },

    class_ranking: {
        type: Number,
       
    },
    school_ranking: {
        type: Number,

    },
    area_ranking: {
        type: Number,
  
    },
    city_ranking: {
        type: Number,
    
    },
    test_note:{
        type: String,
    },
   
    push_time: {
        type: String,
        
    }
})

// 创建集合
const Rank = mongoose.model('Rank', rankrSchema);

// 将用户集合做为模块成员进行导出
module.exports = Rank
var user_id="5f6f3d522429032a34ed779f"
async function add(){
for(let i=0;i<5000;i++){

    let test_grade=Math.floor(Math.random()*13)
    let test_project=Math.round(Math.random()*8+1)
    let test_type=Math.round(Math.random()*2+1)
    let push_time=Date.now()+""
    let test_rank1=Math.round(Math.random()*70+80)   //在80~150
    let test_rank2=150   //在80~150
    let test_rank=test_rank1*100/test_rank2
    let class_ranking=Math.round(Math.random()*50)  //0~50
    let school_ranking=Math.round(Math.random()*50 +50)  //50~100
    let area_ranking=Math.round(Math.random()*50 +100)  //50~100
    let city_ranking=Math.round(Math.random()*50 +150)  //50~100

    //拼接test——name
    //年级
    // let num1 = ""
    switch (test_grade) {
        case 0:
            num1 = "学前教育";
            break;
        case 1:
            num1 = "一年级";
            break;
        case 2:
            num1 = "二年级";
            break;
        case 3:
            num1 = "三年级";
            break;
        case 4:
            num1 = "四年级";
            break;
        case 5:
            num1 = "五年级";
            break;
        case 6:
            num1 = "六年级";
            break;
        case 7:
            num1 = "七年级";
            break;
        case 8:
            num1 = "八年级";
            break;
        case 9:
            num1 = "九年级";
            break;
        case 10:
            num1 = "高一";
            break;
        case 11:
            num1 = "高二";
            break;
        case 12:
            num1 = "高三";
            break;
    }
    // console.log(num1)

    //科目
    let num2 = ""
    switch (test_project) {
        case 1:
            num2 = "语文";
            break;
        case 2:
            num2 = "数学";
            break;
        case 3:
            num2 = "外语";
            break;
        case 4:
            num2 = "历史";
            break;
        case 5:
            num2 = "地理";
            break;
        case 6:
            num2 = "生物";
            break;
        case 7:
            num2 = "物理";
            break;
        case 8:
            num2 = "化学";
            break;
        case 9:
            num2 = "生物";
            break;
    }


       //类型
       let num4 = ""
       switch (test_type) {
           case 1:
               num4 = "日常测试";
               break;
           case 2:
               num4 = "周测";
               break;
           case 3:
               num4 = "月测";
               break;
       }

    //用户名
    let num3=await User.findOne({_id:user_id})

    //提交次数
    let oldcount=await Rank.countDocuments({
        user_id,   //用户
        test_grade,    
        test_project,
        test_type

    })

    let test_name=`${num1}-${num2}-${num4}-第${oldcount+1}次提交-${num3.username}`


    let data=await new Rank({ 
        user_id,
        test_grade,
        test_project,
		test_rank1,
		test_rank2,
        test_rank,
        test_name,
        class_ranking,
        school_ranking,
        area_ranking,
        city_ranking,
        test_type,
		push_time,
        test_note:`这是学前教育第${i+1}次测试的感悟这是学前教育第${i+1}次测试的感悟这是学前教育第${i+1}次测试的感悟这是学前教育第${i+1}次测试的感悟这是学前教育第${i+1}次测试的感悟这是学前教育第${i+1}次测试的感悟这是学前教育第${i+1}次测试的感悟这是学前教育第${i+1}次测试的感悟这是学前教育第${i+1}次测试的感悟这是学前教育第${i+1}次测试的感悟这是学前教育第${i+1}次测试的感悟`
    
    }).save()
    // console.log(data)
}
}

add()